#ifndef EXPLOSION_H
#define EXPLOSION_H

#include "../sprite_handler.h"

typedef struct STRUCT_EXPLO_DATA
{
	int map_position_x, map_position_y;
} ExplosionData;

#define EXPLOSION_ANIM_INDEX 0

void newExplosion( int x, int y )
{
	 // create new sprite handler for turret
	SpriteHandler * explosion = newSpriteHandler();
	
	explosion->characterType = CHAR_EXPLOSION;
	
	// TODO: Set Animations
	
	// Set userdata
	ExplosionData * explo_data = malloc( sizeof( ExplosionData ) );	
	memset( explo_data, 0, sizeof( ExplosionData ) ); // Zero set the userdata
	
	explo_data->map_position_x = x;
	explo_data->map_position_y = y;
	
	explosion->userData = explo_data; // Set the user data
	explosion->_imageIndex = FRAME_EXPLOSION_1;
	explosion->size = SD_16x16;
	explosion->x = x;
	explosion->y = y;
	
	// Add Sprite Animation
	AnimationInfo anim;
	
	anim.updatesPerFrame = 25;
	anim.numFrames = 4;
	anim.looping = FALSE;
	anim.flip = FLIP_NONE;
	anim.frames[ 0 ] = FRAME_EXPLOSION_1;
	anim.frames[ 1 ] = FRAME_EXPLOSION_2;
	anim.frames[ 2 ] = FRAME_EXPLOSION_3;
	anim.frames[ 3 ] = FRAME_EXPLOSION_4;
	
	AddSpriteAnimation( explosion, EXPLOSION_ANIM_INDEX, anim );
	
	SetSpriteAnimation( explosion, EXPLOSION_ANIM_INDEX );	// set animation
	
	updateSpriteAttributes( explosion );
}

void updateExplosion( SpriteHandler * explosion )
{
	// update animation
	UpdateSpriteAnimation( explosion );
	//updateSpriteAttributes( explosion );
	// unsigned short* pcav = 0x3000000;
	// *pcav = 1;
	// if animation is over, kill self
	if ( explosion->animationComplete )
	{
		explosion->alive = FALSE;
		updateSpriteAttributes( explosion );
	}
}

#endif
